import os
import pandas as pd

name_list=['算法','数据挖掘','图像']
class_list=['1班','2班','3班']
for name1 in name_list:
    for class2 in class_list:
        print('正在分离\'{}\'的'.format(name1)+format(class2)+'数据')
        input_file='./data4_1_classify_name/{}.xlsx'.format(name1)
        output_file = './data4_2_classify_class/{}'.format(name1) + format(class2)+".xlsx"
        directory = 'data4_2_classify_class'
        if not os.path.exists(directory):
            os.makedirs(directory)
        data1=pd.read_excel(input_file)
        # if 'Unnamed: 0' in df.columns:
        data1 = data1.drop('Unnamed: 0', axis=1)
        data1=data1.values
        name = []
        class1 = []
        sex = []
        math = []
        Chinese = []
        for item in data1:
            if class2 in item[1]:
                name.append(item[0])
                class1.append(item[1])
                sex.append(item[2])
                math.append(item[3])
                Chinese.append(item[4])
            data2 = {"name": name, 'class1': class1, 'sex': sex, "math": math, "Chinese": Chinese}
            data2=pd.DataFrame(data2)
            data2.to_excel(output_file)
            print(data2)